<?php

if ($this->isAjax == 1 && $this->numChild == 0){
    echo "0";
}else{

?>


<div id="div_content">
    <div class="page-header">
        <h1>
            Pohon Jaringan
            <small>
                <i class="icon-double-angle-right"></i>
                Pohon Jaringan
            </small>
        </h1>
    </div>


    <div class="row">
        <div class="col-xs-11">
            <!-- PAGE CONTENT BEGINS -->

            <ul id="organisation" class="hide">
                <?php echo $this->matrix; ?>

            </ul>

            <div align="center" id="upline"></div>
            <div id="main"></div>

            <!-- PAGE CONTENT ENDS -->
        </div>
    </div>
</div>
<script>

<?php

if ($this->sponsorId > 0) {
?>
$(function() {
    $("#organisation_sponsor").orgChart({
        container: $("#main_sponsor")
        ,stack      : true
    });

});
<?php } ?>

$(function() {
    $("#organisation").orgChart({
        container: $("#main")
        ,stack      : true
        //,interactive: true
        ,nodeClicked: onChartNodeClicked
    });

    $(function(){
        $("[title]").tipTip();
    });


});




function onChartNodeClicked($node) {
    //alert($node.data("actor"));
    if ($node.data("actor") != undefined){
        //location.href = $node.data("actor");

        getChild($node.data("actor"));

    }
}


function getChild(data) {

    var arrData = data.split("-");
    
    if (arrData[0] == "add"){
        location.href='<?php echo $this->url() ?>/../../member/add?parent='+arrData[1];
    }else{

        $.ajax({
            url: '/network/trinary',
            type: "post",
            data: {key : arrData[1], ajax: 1},
            success: function(response, opts){

                if (response != "0"){
                    var cekSess = response.toUpperCase().search('<span class="red">Login</span>');

                    if (cekSess < 0){
                        $("#div_content").html(response);
                    }else{
                        location.href='<?php echo $this->url() ?>/../application/Index/login';
                    }
                }else alert("Tidak memiliki member");

            },
            error:function(response, opts){
                //alert("failure");
                $("#div_content").html(response);

            }
        });
    }

};

function getTreeChild(data) {

    $.ajax({
        url: '/member/treenary/',
        type: "post",
        data: {key : data, ajax: 1},
        success: function(response, opts){

            var cekSess = response.toUpperCase().search('<span class="red">Login</span>');

            if (cekSess < 0){
                $("#div_content").html(response);
            }else{
                location.href='<?php echo $this->url() ?>/../application/Index/login';
            }

        },
        error:function(response, opts){
            //alert("failure");
            $("#div_content").html(response);

        }
    });

};


<?php
if ($this->parent == 1){
    ?>
        document.getElementById('upline').innerHTML = document.getElementById('uplineContent').innerHTML;
<?php
}
?>
</script>

<?php } ?>